﻿using System;
using System.Windows;
using System.Windows.Media;

namespace LineChartControlTest
{
    /// <summary>
    /// Interaction logic for XYChart.xaml
    /// </summary>
    public partial class LineChart : Window
    {
        public LineChart()
        {
            InitializeComponent();
            myLineChart.ChartPanel.AddYAxis("Sine-B", Brushes.Red, 1.2, -1.2);
            myLineChart.ChartPanel.AddYAxis("Spline", Brushes.Green, 12.0, 0);
            myLineChart.ChartPanel.AddYAxis("Cosine", Brushes.Tomato, 1.8, -1.8);
            myLineChart.ChartPanel.AddYAxis("Sine-L", Brushes.Violet, 2.1, -2.1);
            AddData();
        }

        private void AddData()
        {
            myLineChart.SeriesCollection.Clear();

            // Draw Sine curve:
            LineCharts.CurveBase ds = new LineCharts.CurveBase();
            ds.LineColor = Brushes.Blue;
            ds.LineThickness = 2;
            ds.RateXValue = 5;
            ds.SeriesName = "Sine";
            ds.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.Diamond;
            ds.Symbols.FillColor = Brushes.Transparent;
            ds.Symbols.BorderColor = ds.LineColor;
            double x = 0;
            double y = 0;
            for (int i = 0; i < 101; i++)
            {
                x = i / 10.0;
                y = Math.Sin(x);
                ds.RawData.Add(x, y);
            }
            myLineChart.SeriesCollection.AddRawData(ds);

            // Draw cosine curve:
            ds = new LineCharts.CurveBase();
            ds.LineColor = myLineChart.YAxises["Cosine"].AxisColor;
            ds.SeriesName = "Cosine";
            ds.RateXValue = 5;
            ds.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.Box;
            ds.Symbols.BorderColor = ds.LineColor;
            ds.Symbols.FillColor = Brushes.Transparent;
            ds.LinePattern = LineCharts.LinePatternEnum.DashDot;
            ds.LineThickness = 3;
            for (int i = 0; i < 101; i++)
            {
                x = i / 10.0;
                y = Math.Cos(x);
                ds.RawData.Add(x, y);
            }
            myLineChart.SeriesCollection.AddRawData(ds, "Cosine");

            LineCharts.InterpolationCurve curve = new LineCharts.InterpolationCurve();
            curve.LineColor = myLineChart.YAxises["Sine-B"].AxisColor;
            curve.InterpolationMode = LineCharts.InterpolationCurve.InterpolationModeEnum.Barycentric;
            curve.SeriesName = "Sine-B";
            curve.RateXValue = 5;
            curve.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.Dot;
            curve.Symbols.BorderColor = curve.LineColor;
            curve.Symbols.FillColor = Brushes.Transparent;
            curve.LinePattern = LineCharts.LinePatternEnum.Dash;
            curve.LineThickness = 2;
            for (int i = 0; i < 11; i++)
            {
                x = i;
                y = Math.Sin(x);
                curve.RawData.Add(x, y);
            }
            myLineChart.SeriesCollection.AddRawData(curve, "Sine-B");
            
            curve = new LineCharts.InterpolationCurve();
            curve.LineColor = myLineChart.YAxises["Sine-L"].AxisColor;
            curve.InterpolationMode = LineCharts.InterpolationCurve.InterpolationModeEnum.Lagrangian;
            curve.SeriesName = "Sine-L";
            curve.RateXValue = 5;
            curve.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.OpenDiamond;
            curve.Symbols.BorderColor = curve.LineColor;
            curve.Symbols.FillColor = Brushes.Transparent;
            curve.LinePattern = LineCharts.LinePatternEnum.Dot;
            curve.LineThickness = 2;
            for (int i = 0; i < 11; i++)
            {
                x = i;
                y = Math.Sin(x);
                curve.RawData.Add(x, y);
            }
            myLineChart.SeriesCollection.AddRawData(curve, "Sine-L");

            LineCharts.InterpolationCurve curve1 = new LineCharts.InterpolationCurve();
            curve1.LineColor = myLineChart.YAxises["Spline"].AxisColor;
            curve1.InterpolationMode = LineCharts.InterpolationCurve.InterpolationModeEnum.Spline;
            curve1.SeriesName = "Spline";
            curve1.RateXValue = 5;
            curve1.Symbols.SymbolType = LineCharts.Symbols.SymbolTypeEnum.Dot;
            curve1.Symbols.BorderColor = curve1.LineColor;
            curve1.Symbols.FillColor = Brushes.Transparent;
            curve1.LinePattern = LineCharts.LinePatternEnum.Dash_X3;
            curve1.LineThickness = 2;
            curve1.RawData.Add(1, 1);
            curve1.RawData.Add(2, 5);
            curve1.RawData.Add(3, 4);
            curve1.RawData.Add(4, 7);
            curve1.RawData.Add(5, 1);
            curve1.RawData.Add(6, 5);
            curve1.RawData.Add(7, 10);

            myLineChart.SeriesCollection.AddRawData(curve1, "Spline");

            myLineChart.IsLegend = true;
            myLineChart.LegendPosition = LineCharts.Legend.LegendPositionEnum.NorthEast;
        }
    }
}
